package com.anyou.mall.fin.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.utils.DateUtils;
import com.anyou.mall.index.param.OrderNumParam;
import com.anyou.mall.index.param.ShopParam2;
import com.anyou.mall.index.vo.Card4Vo;
import com.anyou.mall.index.vo.IncomOutVo;
import com.anyou.mall.index.vo.OrderNumTjVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.fin.mapper.FinancialDataMapper;
import com.anyou.mall.fin.domain.FinancialData;
import com.anyou.mall.fin.service.IFinancialDataService;

/**
 * 财务数据Service业务层处理
 *
 * @author gaochaohao
 * @date 2022-04-19
 */
@Service
public class FinancialDataServiceImpl implements IFinancialDataService
{
    @Autowired
    private FinancialDataMapper financialDataMapper;


    /**
     * 财务数据4卡片
     * @param param
     * @return
     */
    @Override
    public ApiResult<Card4Vo> card4(ShopParam2 param) {
        Card4Vo card4Vo = new Card4Vo(new BigDecimal(0),new BigDecimal(0),new BigDecimal(0),new BigDecimal(0));

        //查询保证金
        IncomOutVo baoVo = financialDataMapper.selectMoneyByType(0, null, 1);
        //查询订单完成总金额
        IncomOutVo orderVo = financialDataMapper.selectMoneyByType(0, null, 0);
        //查询商家提现总金额
        IncomOutVo tixVo = financialDataMapper.selectMoneyByType(1, 3, null);
        //查询用户退款总金额
        IncomOutVo tugVo = financialDataMapper.selectMoneyByType(1, 0, null);
        if(baoVo!=null){
            card4Vo.setBondMoney(baoVo.getInMoney());
        }
        if(orderVo!=null){
            card4Vo.setOrderMoney(orderVo.getInMoney());
        }
        if(tixVo!=null){
            card4Vo.setTixMoney(tixVo.getOutMoney());
        }
        if(tugVo!=null){
            card4Vo.setTgMoney(tugVo.getOutMoney());
        }
        return ApiResult.success(card4Vo);
    }

    /**
     * 每日提现金额统计折线图
     * @param param
     * @return
     */
    @Override
    public ApiResult<List<OrderNumTjVo>> tixTj(OrderNumParam param) {
        List<OrderNumTjVo> list=financialDataMapper.selectTixTj(param);
        return ApiResult.success(list);
    }

    /**
     * 每日用户退款金额统计折线图
     * @param param
     * @return
     */
    @Override
    public ApiResult<List<OrderNumTjVo>> tugTj(OrderNumParam param) {
        List<OrderNumTjVo> list=financialDataMapper.selectTugTj(param);
        return ApiResult.success(list);
    }
}
